package com.etc.controller;

import com.etc.service.PaymentService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author kalista
 * @Description
 * @Date 2021/5/13  17:11
 **/
@DefaultProperties(defaultFallback = "Global_fallback")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private PaymentService paymentService;

    @GetMapping("/payment/ok/{id}")
    public  Integer ok(@PathVariable("id") Integer id){
       return  paymentService.ok(id);
    }


    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
    })
    @GetMapping("/payment/timeout")
    public String timeout(){
        return paymentService.timeout();
    }


    public String Global_fallback(){
        return "全局的异常稍后在试一试........O(Π___Π)O";
    }
}
